package com.leo.websocketdemo.controller;

import com.alibaba.fastjson.JSONObject;
import com.leo.websocketdemo.entity.Message;
import com.leo.websocketdemo.service.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Administrator
 */
@RestController
public class TestController {
    @Autowired
    private WebSocketServer webSocketServer;

    @RequestMapping("sendMessage")
    public void sendMessage() {
        System.out.println("发送消息。。。。。。");
        Message message = new Message();
        message.setId(1);
        message.setTitle("你好！");
        message.setContent("你好，我是系统管理员。。。。");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("message", message);

        webSocketServer.sendInfo("20", jsonObject.toJSONString());

    }
}
